﻿using GodSystemBLL;
using GodSystemModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GodSystem.FormChildren
{
    public partial class FormAddRoles : Form
    {
        public FormAddRoles()
        {
            InitializeComponent();
        }

        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void button_Add_Click(object sender, EventArgs e)
        {
            string roleName = textBox_RoleName.Text.Trim();
            if (string.IsNullOrEmpty(roleName))
            {
                MessageBox.Show("角色名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            RolesModel rolesModel = new RolesModel();
            rolesModel.RoleName = roleName;
            RolesBLL rolesBLL = new RolesBLL();
            int count = Convert.ToInt32(rolesBLL.GetRole(rolesModel));
            if(count > 0)
            {
                MessageBox.Show("角色名称已经存在，禁止添加相同的名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int addNum = rolesBLL.AddRole(rolesModel);
            if(addNum > 0)
            {
                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox_RoleName.Text = "";
            }
            else
            {
                MessageBox.Show("添加失败,请稍后再试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}
